package com.hospital.workstation.utils;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.hospital.common.exception.ServiceException;
import com.hospital.common.utils.StringUtils;
import com.hospital.workstation.domain.bo.TcmExportBo;
import com.hospital.workstation.domain.bo.TcmRecommendPrescriptionBo;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class WordUtil {
    /**
     * U:方框x
     *  □
     * @param args
     */
    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("monitorRecordNo","{}");
        map.put("hospitalNo","23");
        map.put("patientNo","345364767343");
        map.put("patientNameAcronym","ZS**");
        map.put("inputFormDate","2024/05/12");
        map.put("branchCenter","第一");
        map.put("hospitalName","中医院");


        map.put("monitorRecordNo1","1234");
        map.put("hospitalNo1","23");
        map.put("patientNo1","345364767343");
        map.put("patientNameAcronym1","ZS**");
        map.put("inputFormDate1","2024/05/12");
        map.put("patientSex","男");
        map.put("birthdate","2024年05月12日");
        map.put("phoneNo","13344445555");
        map.put("patientHeight","123");
        map.put("patientWeight","050");
        map.put("nation","汉");
        map.put("weather","晴");
        map.put("temperature","25");




        map.put("33",new TextRenderData("U",new Style("Wingdings 2",13)));


        String outPath = "C:\\Users\\HYZ\\Desktop\\Test22.docx";

        export(map,outPath);
    }

    public static void export(Map<String, Object> datas,String outPath) {
        try {
            // 处方审核结果数据集合
//            Map<String, Object> datas = new HashMap<>();
            // 患者基本信息
            // 病案号

            // 创建循环策略和配置
            LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
            Configure config = Configure.builder()
                /*.bind("tcmDiagInfoBoList", policy)
                .bind("tcmRecommendPrescriptionBoList", policy)*/
                .build();

            ResourceLoader resourceLoader = new DefaultResourceLoader();
            Resource resource = resourceLoader.getResource("classpath:template/A.docx");
            InputStream inputStream = resource.getInputStream();
            XWPFTemplate template = XWPFTemplate.compile(inputStream, config).render(datas);
            template.writeToFile(outPath);



        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("导出失败");
        }
    }


    //java在word中插入带圈字符




}
